﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="html" indent="yes"/>

  <xsl:template match="/">
    <html>
      <head>
        <title>
          <xsl:value-of select="@title"/>
        </title>
      </head>
      <body>
        <xsl:for-each select="/document/menu-item">
          <xsl:call-template name="tpl-menu-item">
            <xsl:with-param name="node" select="."/>
          </xsl:call-template>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="tpl-menu-item">
    <xsl:param name="node"/>
    <xsl:choose>
      <xsl:when test="count($node/menu-item) &gt; 0">
        <dd>
          <xsl:value-of select="@title"/>(<xsl:value-of select="@name"/>)
          <dl>
            <xsl:for-each select="$node/menu-item">
              <xsl:call-template name="tpl-menu-item">
                <xsl:with-param name="node" select="."/>
              </xsl:call-template>
            </xsl:for-each>
          </dl>
        </dd>
      </xsl:when>
      <xsl:otherwise>
        <dd>

          <xsl:call-template name="tpl-menu-content">
            <xsl:with-param name="node" select="."/>
          </xsl:call-template>
        </dd>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="tpl-menu-content">
    <xsl:param name="node"/>
    <div>
      <div>
        <xsl:value-of select="$node/@title"/>(<xsl:value-of select="@name"/>)
      </div>
      <table cellpadding="2" cellspacing="1" border="0" style="margin-left:2em">
        <tbody>
          <tr>
            <th style="text-align:right">动作</th>
            <td>
              <xsl:value-of select="@action"/>
            </td>
          </tr>
          <tr>
            <th style="text-align:right">模型</th>
            <td>
              <strong>
                [<xsl:value-of select="@module"/>]
              </strong>
              <i>
                <xsl:value-of select="@model"/>
              </i>
            </td>
          </tr>
          <tr>
            <th style="text-align:right">视图</th>
            <td>
              <xsl:for-each select="$node/views/view">
                <div>
                  <strong>
                    [<xsl:value-of select="@type"/>]:
                  </strong>
                  <span style="font-family:'Courier New';color:red">
                    <xsl:value-of select="@name"/>
                  </span>
                </div>
              </xsl:for-each>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </xsl:template>
</xsl:stylesheet>
